package com.os.config;

import org.apache.http.HttpHost;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenSearchConfig {

    @Bean
    public RestHighLevelClient client() {
        // OpenSearch 客户端连接
        RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "http"));

        // 配置连接池等
//        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
//        connectionManager.setMaxTotal(100);
//        connectionManager.setDefaultMaxPerRoute(20);
//
        return new RestHighLevelClient(builder);
    }
}
